{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e9c2b61c-b4e2-45eb-8da1-f8221c60993b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-14T23:46:53.030341Z",
     "iopub.status.busy": "2022-05-14T23:46:53.029941Z",
     "iopub.status.idle": "2022-05-14T23:46:53.560135Z",
     "shell.execute_reply": "2022-05-14T23:46:53.559671Z",
     "shell.execute_reply.started": "2022-05-14T23:46:53.030274Z"
    }
   },
   "outputs": [],
   "source": [
    "# 导入包\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "30b9cdcf-a153-4f8a-9e74-ada24687f330",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-14T23:51:13.053979Z",
     "iopub.status.busy": "2022-05-14T23:51:13.053647Z",
     "iopub.status.idle": "2022-05-14T23:51:13.082541Z",
     "shell.execute_reply": "2022-05-14T23:51:13.081899Z",
     "shell.execute_reply.started": "2022-05-14T23:51:13.053953Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>leixing</th>\n",
       "      <th>nianfen</th>\n",
       "      <th>licheng</th>\n",
       "      <th>didian</th>\n",
       "      <th>shoujia</th>\n",
       "      <th>yuanjia</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>凯迪拉克ATS-L 2016款 28T 时尚型</td>\n",
       "      <td>2016年</td>\n",
       "      <td>2.5万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>16.77万</td>\n",
       "      <td>34.60万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪A6L 2014款 TFSI 标准型</td>\n",
       "      <td>2014年</td>\n",
       "      <td>13.8万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>21.96万</td>\n",
       "      <td>44.50万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>本田 思域 2016款 1.8L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>4.8万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>8.87万</td>\n",
       "      <td>15.20万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>大众 朗逸 2015款 1.6L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>10.5万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>7.27万</td>\n",
       "      <td>14.90万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>leixing</td>\n",
       "      <td>nianfen</td>\n",
       "      <td>licheng</td>\n",
       "      <td>didian</td>\n",
       "      <td>shoujia</td>\n",
       "      <td>yuanjia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2005</th>\n",
       "      <td>大众 途观 2013款 1.8TSI 自动两驱舒适版</td>\n",
       "      <td>2014年</td>\n",
       "      <td>7.3万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>13.50万</td>\n",
       "      <td>25.80万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006</th>\n",
       "      <td>现代ix35 2012款 2.0L 自动两驱精英版GLS</td>\n",
       "      <td>2012年</td>\n",
       "      <td>7.1万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>8.00万</td>\n",
       "      <td>21.30万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007</th>\n",
       "      <td>宝马3系 2014款 320Li 时尚型</td>\n",
       "      <td>2015年</td>\n",
       "      <td>4.6万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>23.00万</td>\n",
       "      <td>38.90万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008</th>\n",
       "      <td>标致308 2014款 乐享版 经典 1.6L 手动优尚型</td>\n",
       "      <td>2015年</td>\n",
       "      <td>3.0万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>6.20万</td>\n",
       "      <td>11.50万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009</th>\n",
       "      <td>大众POLO 2014款 1.6L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>2.9万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>7.40万</td>\n",
       "      <td>11.30万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2010 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            leixing  nianfen  licheng  didian  shoujia  \\\n",
       "0           凯迪拉克ATS-L 2016款 28T 时尚型    2016年   2.5万公里      长沙   16.77万   \n",
       "1              奥迪A6L 2014款 TFSI 标准型    2014年  13.8万公里      长沙   21.96万   \n",
       "2            本田 思域 2016款 1.8L 自动舒适版    2016年   4.8万公里      长沙    8.87万   \n",
       "3            大众 朗逸 2015款 1.6L 自动舒适版    2016年  10.5万公里      长沙    7.27万   \n",
       "4                           leixing  nianfen  licheng  didian  shoujia   \n",
       "...                             ...      ...      ...     ...      ...   \n",
       "2005     大众 途观 2013款 1.8TSI 自动两驱舒适版    2014年   7.3万公里      长沙   13.50万   \n",
       "2006   现代ix35 2012款 2.0L 自动两驱精英版GLS    2012年   7.1万公里      长沙    8.00万   \n",
       "2007           宝马3系 2014款 320Li 时尚型    2015年   4.6万公里      长沙   23.00万   \n",
       "2008  标致308 2014款 乐享版 经典 1.6L 手动优尚型    2015年   3.0万公里      长沙    6.20万   \n",
       "2009        大众POLO 2014款 1.6L 自动舒适版    2016年   2.9万公里      长沙    7.40万   \n",
       "\n",
       "      yuanjia  \n",
       "0      34.60万  \n",
       "1      44.50万  \n",
       "2      15.20万  \n",
       "3      14.90万  \n",
       "4     yuanjia  \n",
       "...       ...  \n",
       "2005   25.80万  \n",
       "2006   21.30万  \n",
       "2007   38.90万  \n",
       "2008   11.50万  \n",
       "2009   11.30万  \n",
       "\n",
       "[2010 rows x 6 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 载入数据\n",
    "data = pd.read_csv(r\"data/practice6.csv\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5cb56593-71e9-4997-8e0c-bf1ec45c8e3f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T01:37:30.090111Z",
     "iopub.status.busy": "2022-05-15T01:37:30.089789Z",
     "iopub.status.idle": "2022-05-15T01:37:30.108702Z",
     "shell.execute_reply": "2022-05-15T01:37:30.108074Z",
     "shell.execute_reply.started": "2022-05-15T01:37:30.090085Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>leixing</th>\n",
       "      <th>nianfen</th>\n",
       "      <th>licheng</th>\n",
       "      <th>didian</th>\n",
       "      <th>shoujia</th>\n",
       "      <th>yuanjia</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>凯迪拉克ATS-L 2016款 28T 时尚型</td>\n",
       "      <td>2016年</td>\n",
       "      <td>2.5万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>16.77万</td>\n",
       "      <td>34.60万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>奥迪A6L 2014款 TFSI 标准型</td>\n",
       "      <td>2014年</td>\n",
       "      <td>13.8万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>21.96万</td>\n",
       "      <td>44.50万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>本田 思域 2016款 1.8L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>4.8万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>8.87万</td>\n",
       "      <td>15.20万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>大众 朗逸 2015款 1.6L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>10.5万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>7.27万</td>\n",
       "      <td>14.90万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>leixing</td>\n",
       "      <td>nianfen</td>\n",
       "      <td>licheng</td>\n",
       "      <td>didian</td>\n",
       "      <td>shoujia</td>\n",
       "      <td>yuanjia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2005</th>\n",
       "      <td>大众 途观 2013款 1.8TSI 自动两驱舒适版</td>\n",
       "      <td>2014年</td>\n",
       "      <td>7.3万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>13.50万</td>\n",
       "      <td>25.80万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006</th>\n",
       "      <td>现代ix35 2012款 2.0L 自动两驱精英版GLS</td>\n",
       "      <td>2012年</td>\n",
       "      <td>7.1万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>8.00万</td>\n",
       "      <td>21.30万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007</th>\n",
       "      <td>宝马3系 2014款 320Li 时尚型</td>\n",
       "      <td>2015年</td>\n",
       "      <td>4.6万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>23.00万</td>\n",
       "      <td>38.90万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008</th>\n",
       "      <td>标致308 2014款 乐享版 经典 1.6L 手动优尚型</td>\n",
       "      <td>2015年</td>\n",
       "      <td>3.0万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>6.20万</td>\n",
       "      <td>11.50万</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009</th>\n",
       "      <td>大众POLO 2014款 1.6L 自动舒适版</td>\n",
       "      <td>2016年</td>\n",
       "      <td>2.9万公里</td>\n",
       "      <td>长沙</td>\n",
       "      <td>7.40万</td>\n",
       "      <td>11.30万</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1937 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            leixing  nianfen  licheng  didian  shoujia  \\\n",
       "0           凯迪拉克ATS-L 2016款 28T 时尚型    2016年   2.5万公里      长沙   16.77万   \n",
       "1              奥迪A6L 2014款 TFSI 标准型    2014年  13.8万公里      长沙   21.96万   \n",
       "2            本田 思域 2016款 1.8L 自动舒适版    2016年   4.8万公里      长沙    8.87万   \n",
       "3            大众 朗逸 2015款 1.6L 自动舒适版    2016年  10.5万公里      长沙    7.27万   \n",
       "4                           leixing  nianfen  licheng  didian  shoujia   \n",
       "...                             ...      ...      ...     ...      ...   \n",
       "2005     大众 途观 2013款 1.8TSI 自动两驱舒适版    2014年   7.3万公里      长沙   13.50万   \n",
       "2006   现代ix35 2012款 2.0L 自动两驱精英版GLS    2012年   7.1万公里      长沙    8.00万   \n",
       "2007           宝马3系 2014款 320Li 时尚型    2015年   4.6万公里      长沙   23.00万   \n",
       "2008  标致308 2014款 乐享版 经典 1.6L 手动优尚型    2015年   3.0万公里      长沙    6.20万   \n",
       "2009        大众POLO 2014款 1.6L 自动舒适版    2016年   2.9万公里      长沙    7.40万   \n",
       "\n",
       "      yuanjia  \n",
       "0      34.60万  \n",
       "1      44.50万  \n",
       "2      15.20万  \n",
       "3      14.90万  \n",
       "4     yuanjia  \n",
       "...       ...  \n",
       "2005   25.80万  \n",
       "2006   21.30万  \n",
       "2007   38.90万  \n",
       "2008   11.50万  \n",
       "2009   11.30万  \n",
       "\n",
       "[1937 rows x 6 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除缺失值\n",
    "data = data.dropna()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "71d59fd1-2710-4864-9f81-23efe00a411b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:16:49.843936Z",
     "iopub.status.busy": "2022-05-15T02:16:49.843593Z",
     "iopub.status.idle": "2022-05-15T02:16:49.855773Z",
     "shell.execute_reply": "2022-05-15T02:16:49.855041Z",
     "shell.execute_reply.started": "2022-05-15T02:16:49.843910Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.977446</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.282399</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "1 -1.977446       NaN       NaN\n",
       "2 -0.282399       NaN       NaN\n",
       "3 -1.037726       NaN -1.656062\n",
       "4 -0.662678       NaN -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构造有空值的DataFrame\n",
    "df = pd.DataFrame(np.random.randn(7,3))\n",
    "df.iloc[1:3,2] = np.nan\n",
    "df.iloc[1:5,1] = np.nan\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "10835b60-24f4-4e5d-aaf1-4799fd972902",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:17:29.043693Z",
     "iopub.status.busy": "2022-05-15T02:17:29.043333Z",
     "iopub.status.idle": "2022-05-15T02:17:29.055568Z",
     "shell.execute_reply": "2022-05-15T02:17:29.054766Z",
     "shell.execute_reply.started": "2022-05-15T02:17:29.043667Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 直接删除nan\n",
    "df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "66b34838-4b3c-4b4c-b1e2-1d1890b155cc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:18:18.916891Z",
     "iopub.status.busy": "2022-05-15T02:18:18.916557Z",
     "iopub.status.idle": "2022-05-15T02:18:18.928779Z",
     "shell.execute_reply": "2022-05-15T02:18:18.928123Z",
     "shell.execute_reply.started": "2022-05-15T02:18:18.916865Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "3 -1.037726       NaN -1.656062\n",
       "4 -0.662678       NaN -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设定nan个数阈值进行删除\n",
    "df.dropna(thresh=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b8fce39a-cedd-411e-ba0e-38494739237d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:24:03.489015Z",
     "iopub.status.busy": "2022-05-15T02:24:03.488687Z",
     "iopub.status.idle": "2022-05-15T02:24:03.498692Z",
     "shell.execute_reply": "2022-05-15T02:24:03.498011Z",
     "shell.execute_reply.started": "2022-05-15T02:24:03.488989Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.977446</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.282399</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "1 -1.977446  1.172978 -0.936919\n",
       "2 -0.282399  1.172978 -0.936919\n",
       "3 -1.037726  1.172978 -1.656062\n",
       "4 -0.662678  1.172978 -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置method填充，使用ffill模式\n",
    "df.fillna(method=\"ffill\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2db34e5b-66ad-4da3-8072-69007f61e954",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:26:38.422881Z",
     "iopub.status.busy": "2022-05-15T02:26:38.422487Z",
     "iopub.status.idle": "2022-05-15T02:26:38.432851Z",
     "shell.execute_reply": "2022-05-15T02:26:38.432108Z",
     "shell.execute_reply.started": "2022-05-15T02:26:38.422854Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.977446</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.282399</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "1 -1.977446 -1.933276 -1.656062\n",
       "2 -0.282399 -1.933276 -1.656062\n",
       "3 -1.037726 -1.933276 -1.656062\n",
       "4 -0.662678 -1.933276 -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置method填充，使用bfill模式\n",
    "df.fillna(method=\"bfill\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c7afb4e0-3cda-49a5-aa2a-eead6fbe160a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:36:16.758737Z",
     "iopub.status.busy": "2022-05-15T02:36:16.758063Z",
     "iopub.status.idle": "2022-05-15T02:36:16.768484Z",
     "shell.execute_reply": "2022-05-15T02:36:16.767756Z",
     "shell.execute_reply.started": "2022-05-15T02:36:16.758715Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.977446</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.282399</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "1 -1.977446  1.172978 -0.936919\n",
       "2 -0.282399       NaN       NaN\n",
       "3 -1.037726       NaN -1.656062\n",
       "4 -0.662678       NaN -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置method填充，limit=1\n",
    "df.fillna(method=\"ffill\", limit=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "59e615ec-cb28-4b2a-b40e-3e04a6e1aee5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-15T02:32:45.199870Z",
     "iopub.status.busy": "2022-05-15T02:32:45.199532Z",
     "iopub.status.idle": "2022-05-15T02:32:45.209764Z",
     "shell.execute_reply": "2022-05-15T02:32:45.209042Z",
     "shell.execute_reply.started": "2022-05-15T02:32:45.199844Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.096196</td>\n",
       "      <td>1.172978</td>\n",
       "      <td>-0.936919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.977446</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.282399</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.037726</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.656062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.662678</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-0.494422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-1.561569</td>\n",
       "      <td>-1.933276</td>\n",
       "      <td>-1.302466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.157165</td>\n",
       "      <td>-1.601146</td>\n",
       "      <td>0.759879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.096196  1.172978 -0.936919\n",
       "1 -1.977446       NaN       NaN\n",
       "2 -0.282399       NaN -1.656062\n",
       "3 -1.037726       NaN -1.656062\n",
       "4 -0.662678 -1.933276 -0.494422\n",
       "5 -1.561569 -1.933276 -1.302466\n",
       "6  1.157165 -1.601146  0.759879"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置method填充，limit=1\n",
    "df.fillna(method=\"bfill\", limit=1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
